package com.android.lovely.room.role

import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import com.kotlin.extensions.appContext
import com.kotlin.extensions.coroutine.applicationScope
import kotlinx.coroutines.launch

/**
 *
 * @author why
 * @date 2025/4/6 17:15
 */
@Database(entities = [CreateRole::class], version = 1)
@TypeConverters(StringConverter::class, CreateConverter::class)
abstract class CreateRoleDataBase : RoomDatabase() {

    companion object {
        private val instance by lazy {
            Room.databaseBuilder(appContext, CreateRoleDataBase::class.java, "lovelyCreate.db").apply {
                allowMainThreadQueries()
                enableMultiInstanceInvalidation()
                fallbackToDestructiveMigration()
                setQueryExecutor { applicationScope.launch { it.run() } }
            }.build()
        }

        val dao get() = instance.dao()

    }

    abstract fun dao(): CreateRoleDao
}